import { shallowRef } from 'vue'

import { getVIPContent } from './api'
import { catchFn } from '@/libs/common'

const list = shallowRef<
  {
    level: number
    name: string
    description: string
  }[]
>([])
const infoList = shallowRef<
  {
    name: string
    content: string
  }[]
>([
  {
    name: '每日打卡分享',
    content: '每日打卡分享得 1 蒜瓣，连续打卡 7 天额外获得 5 蒜瓣',
  },
  {
    name: '邀请好友注册',
    content: '邀请好友注册成功得 3 蒜瓣，邀请好友成功注册达 5 人额外获得 8 蒜瓣',
  },
  {
    name: '邀请好友付费',
    content: '邀请好友付费得 10 蒜瓣，邀请好友付费累计 198 元 可享受分销机制成为推广员得现金奖励',
  },
])

export { list, infoList }

/**
 * 更新会员权益
 */
const updateVIPContent = () =>
  catchFn(async () => {
    const { data } = await getVIPContent()

    list.value = data
  })

export { updateVIPContent }
